package com.example.wk.zyfypt_218wk.model;

import com.example.wk.zyfypt_218wk.bean.LoginBean;
import com.example.wk.zyfypt_218wk.iface.LoginListener;
import com.example.wk.zyfypt_218wk.iface.Loginiface;
import com.example.wk.zyfypt_218wk.service.LoginService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by wk on 2017/5/2.
 */

public class LoginModel implements Loginiface{

    private Retrofit retrofit;
    private String BASEURL = "http://amicool.neusoft.edu.cn/";

    public LoginModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }


    @Override
    public void getResultList(String username, String password, final LoginListener listener) {
        LoginService loginService=retrofit.create(LoginService.class);
        Call<LoginBean> call =loginService.getResult(username,password);
        call.enqueue(new Callback<LoginBean>() {
            @Override
            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
                listener.onResponse(response.body());
            }
            @Override
            public void onFailure(Call<LoginBean> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
